<template>

  <div id="pageMain">

    <div id="area01">

      <div class="apply">
        <div class="title">场所码申领</div>
        <div class="today">
          <div class="item">
            <div class="title">今日申领场所码</div>
            <div class="content">2764万<span class="unit">个</span></div>
          </div>
          <div class="item">
            <div class="title">今日新增申领机构</div>
            <div class="content">3000<span class="unit">个</span></div>
          </div>
          <div class="item">
            <div class="title">今日活跃场所码</div>
            <div class="content">1.5亿<span class="unit">个</span></div>
          </div>
        </div>

        <div class="all">
          <div class="left">
            <div class="item">
              <div class="title">累计申领场所码</div>
              <div class="content">230万<span class="unit">个</span></div>
            </div>
            <div class="item">
              <div class="title">累计注册机构</div>
              <div class="content">150万<span class="unit">个</span></div>
            </div>
            <div class="item">
              <div class="title">累计注册场所</div>
              <div class="content">280万<span class="unit">个</span></div>
            </div>
            <div class="item">
              <div class="title">累计预警场所</div>
              <div class="content">23<span class="unit">个</span></div>
            </div>
          </div>
          <div class="right">
            <div class="title">
              <div class="text">地区申请场所码统计</div>
              <div class="type">
                <select>
                  <option value="1">累计排行</option>
                  <option value="2">今日排行</option>
                </select>
              </div>
            </div>
          <div id="areaChart"></div>
          </div>
        </div>

      </div>
      <div class="warning">
        <div class="title">动态预警信息</div>
        <div class="content">
          <table>
            <tr>
              <th width="23%">场所名称</th>
              <th width="22%">预警时间</th>
              <th width="20%">预警类别</th>
              <th width="23%">预警区域</th>
              <th width="12%">操作</th>
            </tr>
            <tbody>
              <tr>
                <td align="center">XXX洗浴中心</td>
                <td align="center">2020-03-13 10:10:20</td>
                <td align="center" class="red">有红色重点人扫码</td>
                <td align="center">贵州贵阳市云岩区</td>
                <td align="center">查看详情</td>
              </tr>
              <tr>
                <td align="center">XXX洗浴中心</td>
                <td align="center">2020-03-13 10:10:20</td>
                <td align="center" class="orange">有黄色重点人扫码</td>
                <td align="center">贵州贵阳市云岩区</td>
                <td align="center">查看详情</td>
              </tr>
              <tr>
                <td align="center">XXX洗浴中心</td>
                <td align="center">2020-03-13 10:10:20</td>
                <td align="center" class="red">有红色重点人扫码</td>
                <td align="center">贵州贵阳市云岩区</td>
                <td align="center">查看详情</td>
              </tr>
              <tr>
                <td align="center">XXX洗浴中心</td>
                <td align="center">2020-03-13 10:10:20</td>
                <td align="center" class="red">有红色重点人扫码</td>
                <td align="center">贵州贵阳市云岩区</td>
                <td align="center">查看详情</td>
              </tr>
              <tr>
                <td align="center">XXX洗浴中心</td>
                <td align="center">2020-03-13 10:10:20</td>
                <td align="center" class="red">扫码地与登记地址不符</td>
                <td align="center">贵州贵阳市云岩区</td>
                <td align="center">查看详情</td>
              </tr>
              <tr>
                <td align="center">XXX洗浴中心</td>
                <td align="center">2020-03-13 10:10:20</td>
                <td align="center" class="red">有红色重点人扫码</td>
                <td align="center">贵州贵阳市云岩区</td>
                <td align="center">查看详情</td>
              </tr>
              <tr>
                <td align="center">XXX洗浴中心</td>
                <td align="center">2020-03-13 10:10:20</td>
                <td align="center" class="red">有红色重点人扫码</td>
                <td align="center">贵州贵阳市云岩区</td>
                <td align="center">查看详情</td>
              </tr>
              <tr>
                <td align="center">XXX洗浴中心</td>
                <td align="center">2020-03-13 10:10:20</td>
                <td align="center" class="red">有红色重点人扫码</td>
                <td align="center">贵州贵阳市云岩区</td>
                <td align="center">查看详情</td>
              </tr>
            </tbody>
          </table>
        </div>
      </div>
    </div>

    <div id="area02">
      <div class="left">
        <div class="title">场所码趋势统计</div>
        <div id="trendChart"></div>
      </div>
      <div class="right">
        <div class="title">场所码类型统计</div>
        <div id="typeChart"></div>
      </div>
    </div>

  </div>

</template>

<script>

import { Bar } from "@antv/g2plot";
import { Area } from "@antv/g2plot";
import { Pie } from '@antv/g2plot';

export default {
  
  data() {
    return {
      //地区申请场所码统计测试数据
      areaChart: [
        { name: "贵阳市", value: 78364, },
        { name: "遵义市", value: 67832 },
        { name: "铜仁市", value: 56738 },
        { name: "毕节市", value: 55923 },
        { name: "六盘水市", value: 49847 },
        { name: "黔东南州", value: 45982 },
        { name: "黔南州", value: 35003 },
        { name: "黔西南州", value: 32913 },
        { name: "安顺市", value: 25003 }
      ],

      //场所码趋势统计
      trendChart: [
        { name: "活跃场所码", date: "4-12", value: 12632, },
        { name: "活跃场所码", date: "4-13", value: 8454 },
        { name: "活跃场所码", date: "4-14", value: 30393 },
        { name: "活跃场所码", date: "4-15", value: 28731 },
        { name: "活跃场所码", date: "4-16", value: 3612 },
        { name: "活跃场所码", date: "4-17", value: 47212 },
        { name: "活跃场所码", date: "4-18", value: 16872 },
        { name: "活跃场所码", date: "4-19", value: 18272 },
        { name: "活跃场所码", date: "4-20", value: 18732 },
        { name: "活跃场所码", date: "4-21", value: 17622 },
        { name: "活跃场所码", date: "4-22", value: 11283 },
        { name: "活跃场所码", date: "4-23", value: 19012 },
        { name: "活跃场所码", date: "4-24", value: 25823 },
        { name: "活跃场所码", date: "4-25", value: 21001 },
        { name: "活跃场所码", date: "4-26", value: 17653 },
        { name: "申领场所码", date: "4-12", value: 13632, },
        { name: "申领场所码", date: "4-13", value: 4454 },
        { name: "申领场所码", date: "4-14", value: 20393 },
        { name: "申领场所码", date: "4-15", value: 29731 },
        { name: "申领场所码", date: "4-16", value: 9612 },
        { name: "申领场所码", date: "4-17", value: 37212 },
        { name: "申领场所码", date: "4-18", value: 36872 },
        { name: "申领场所码", date: "4-19", value: 28272 },
        { name: "申领场所码", date: "4-20", value: 28732 },
        { name: "申领场所码", date: "4-21", value: 27622 },
        { name: "申领场所码", date: "4-22", value: 11283 },
        { name: "申领场所码", date: "4-23", value: 13012 },
        { name: "申领场所码", date: "4-24", value: 29823 },
        { name: "申领场所码", date: "4-25", value: 28001 },
        { name: "申领场所码", date: "4-26", value: 14653 }
      ],

      //场所码类型统计
      typeChart: [
        { name: "社会服务和管理机构", value: 364, },
        { name: "商贸场所", value: 832 },
        { name: "住宿与消费场所", value: 738 },
        { name: "公共交通", value: 1023 },
        { name: "居住场所", value: 847 },
        { name: "其他场所", value: 682 }
      ],
    }
  },

  mounted: function(){
      this.initAreaChart();
      this.initTrendChart();
      this.initTypeChart();
  },

  methods: {

    //初始化地区申请场所码统计
    initAreaChart: function (){
      let _this = this;
      let data = _this.areaChart;
      const barPlot = new Bar("areaChart", {
        data,
        xField: "value",
        yField: "name",
        padding: [10, 50, 20, 100],
        label: {
          position: "right",
          offset: 5,
        },
        color: "#5cdebf",
        meta: {
          name: {
            alias: "地区",
          },
          value: {
            alias: "申请数量",
          },
        },
      });
      barPlot.render();
    },

    //初始化场所码趋势统计
    initTrendChart: function (){
      let _this = this;
      let data = _this.trendChart;
      const area = new Area("trendChart", {
        data,
        xField: "date",
        yField: "value",
        seriesField: "name",
        meta: {
          value: {
            formatter: (v) => `${v} 个`,
            
          },
        },
        areaStyle: (type) => {
        return {
            fill: type.name == "活跃场所码" ?
            "l(270) 0:#ffffff 0.5:#7ec2f3 1:#1890ff":
            "l(270) 0:#ffffff 0.5:#a0d8cb 1:#5cdebf",
          };
        },
      });
      area.render();
    },

    //初始化场所码类型统计
    initTypeChart: function (){
      let _this = this;
      let data = _this.typeChart;
      const piePlot = new Pie("typeChart", {
        appendPadding: 10,
        data,
        angleField: "value",
        colorField: "name",
        radius: 1,
        innerRadius: 0.64,
        meta: {
          value: {
            formatter: (v) => `${v} 个`,
            
          },
        },
        label: {
          type: "inner",
          offset: "-50%",
          autoRotate: false,
          style: { textAlign: "center",  fontSize: "14"},
          formatter: ({ percent }) => `${(percent * 100).toFixed(1)}%`,
        },
        statistic: {
          title: {
            offsetY: -8,
          },
          content: {
            offsetY: -4,
          },
        },
        // 添加 中心统计文本 交互
        interactions: [
          { type: 'element-selected' },
          { type: 'element-active' },
          {
            type: 'pie-statistic-active',
            cfg: {
              start: [
                { trigger: 'element:mouseenter', action: 'pie-statistic:change' },
                { trigger: 'legend-item:mouseenter', action: 'pie-statistic:change' },
              ],
              end: [
                { trigger: 'element:mouseleave', action: 'pie-statistic:reset' },
                { trigger: 'legend-item:mouseleave', action: 'pie-statistic:reset' },
              ],
            },
          },
        ],
      });
      piePlot.render();
    }


  }
}
</script>

<style scoped>

  #pageMain{
    padding-bottom: 10px;
  }

  /******** 场所码申领 与 动态预警信息 *********/  

  #area01{
    background-color: white;
    border-radius: 10px;
    margin: 10px;
    padding: 20px;
    display: flex;
    box-shadow: 0px 0px 7px rgba(0, 0, 0, 0.1);
  }

  /******** 场所码申领 > 今日 *********/

  #area01 > .apply{
    flex: 1;
  }

  #area01 > .apply > .title{
    font-size: 1.5rem;
  }

  #area01 > .apply > .today{
    display: flex;
    margin-top: 20px;
    border-bottom: solid 1px #e0e0e0;
    padding-bottom: 20px;
  }

  #area01 > .apply > .today > .item{
    flex: 1;
    background-color: #ebf5ff;
    padding: 10px;
    border-radius: 10px;
    margin-right: 20px;
  }

  #area01 > .apply > .today > .item:last-child{
    margin-right: 0px;
  }

  #area01 > .apply > .today > .item > .content{
    font-size: 1.5rem;
    color: #015478;
    font-weight: bold;
  }

  #area01 > .apply > .today > .item > .content > .unit{
    font-size: 0.9rem;
    color: black;
    font-weight: normal;
    padding-left: 5px;
  }

  /******** 场所码申领 > 累计 *********/

  #area01 > .apply > .all{
    display: flex;
  }

  #area01 > .apply > .all > .left{
    flex: 4;
  }

  #area01 > .apply > .all > .left > .item{
    background-color: #ebf5ff;
    padding: 10px;
    border-radius: 10px;
    margin-top: 20px;
  }

  #area01 > .apply > .all > .left > .item > .content{
    font-size: 1.5rem;
    color: #015478;
    font-weight: bold;
  }

  #area01 > .apply > .all > .left > .item > .content > .unit{
    font-size: 0.9rem;
    color: black;
    font-weight: normal;
    padding-left: 5px;
  }

  #area01 > .apply > .all > .right{
    flex: 6;
  }

  #area01 > .apply > .all > .right > .title{
    display: flex;
    justify-content: space-around;
    align-items: center;
    margin-top: 20px;
  }

  #areaChart{
    height: 320px;
  }

  /******** 动态预警信息 *********/

  #area01 > .warning{
    flex: 1;
    margin-left: 20px;
  }

  #area01 > .warning > .title{
    font-size: 1.5rem;
  }

  #area01 > .warning > .content{
    margin-top: 20px;
  }

  #area01 > .warning > .content > table{
    width: 100%;
  }

  #area01 > .warning > .content > table th{
    padding:10px 0px 10px 0px;
    color: #015478;
  }

  #area01 > .warning > .content > table > tbody{
    font-size: 0.7rem;
  }

  #area01 > .warning > .content > table > tbody > tr:nth-child(even){
    background-color: #f2f9ff;
  }

  #area01 > .warning > .content > table > tbody > tr:nth-child(odd){
    background-color: #ebf5ff;
  }

  #area01 > .warning > .content > table > tbody > tr:hover{
    background-color: #f9fcff;
  }

  #area01 > .warning > .content > table td{
    padding:15px 5px 15px 5px;
	  word-break: break-all;
  }

  #area01 > .warning > .content > table .red{
    color: red;
  }

  #area01 > .warning > .content > table .orange{
    color: orange;
  }

  /******** 场所码趋势统计 与 场所码类型统计 *********/  

  #area02{
    background-color: white;
    border-radius: 10px;
    margin: 10px 10px 0px 10px;
    padding: 20px;
    display: flex;
    box-shadow: 0px 0px 7px rgba(0, 0, 0, 0.1);
    display: flex;
  }

  /******** 场所码趋势统计 *********/  

  #area02 > .left{
    flex: 6;
  }

  #area02 > .left > .title{
    font-size: 1.5rem;
  }
  
  #trendChart{
    margin-top: 20px;
  }

/******** 场所码类型统计 *********/  

  #area02 > .right{
    flex: 4;
    margin: 0px 20px 0px 20px;
  }

  #area02 > .right > .title{
    font-size: 1.5rem;
  }

  #typeChart{
    margin-top: 20px;
  }

</style>